# chlang - experimental "change language" -dialog
#
# CONTENTS:
#	chlang
#		Shows a "Change language" -dialog, and sets the
#		application language. For translations to show
#		here, they must identify themselves in po/langs.tcl
#		Takes no arguments
#
#	chlang_callback
#		A callback for [chlang]'s "Set" button, changes the
#		language and requests the user to restart. Takes no
#		arguments.

proc chlang {} {
	global LANGS
	
	toplevel .chlang
	ttk::treeview .chlang.list -columns {title}
	.chlang.list heading title -text [tr "Change language"]
	ttk::button .chlang.set -text [tr "Set"] -command chlang_callback
	
	grid rowconfigure .chlang 0 -weight 1
	grid .chlang.list -sticky nsew
	grid .chlang.set -sticky ew
	
	.chlang.list configure -show {headings}

	foreach li [array names LANGS] {
		.chlang.list insert {} end -values "$LANGS($li)"
	}
}

proc chlang_callback {} {
	global CONFIG LANGS
	
	set sel [.chlang.list selection]
	
	foreach lang [array names LANGS] {
		if { $LANGS($lang) == [.chlang.list item $sel -values] } {
			set CONFIG(lang) $lang
		}
	}
	
	saveconfig
	
	tk_dialog .chlang_notify [tr "Notice"] [tr "You must restart the application for changes to take effect."] info 0 [tr "OK"]
	
	destroy .chlang.list .chlang.set .chlang
}
